home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
DDJMAG
/
DDJ9310.ZIP
/
1993-OCT.ZIP
/
LIANA.ASC
< prev
next >
Wrap
Text File
|
1993-09-17
|
8KB
|
260 lines
_THE LIANA PROGRAMMING LANGUAGE_
by Ray Valdes
[LISTING ONE]
//----- Liana program that uses Windows controls in a dialog. ------
main
{ window ();
w.menu = new menu
<< new menuitem ("&Language Info...");
cr = "\n";
d = new language_info_dialog;
d.lang_name = "Liana";
d.language_type = "object-oriented";
d.provides_app_framework = true;
d.has_ide = false;
}
language_info { if (d.show) w.refresh; }
paint
{ w.home;
if (d)
w << " Language name: " + d.lang_name + cr
+ " Language type: " + d.language_type + cr
+ " Provides app framework: " + d.provides_app_framework + cr
+ " Has IDE: " + d.has_ide;
}
class language_info_dialog: dialog
{
public:
string lang_name,
language_type;
bool provides_app_framework,
has_ide;
language_info_dialog
{
dialog ();
this << new labeltext ("Language name:")
<< new edittext (20, "lang_name");
this [0].under;
south ();
this << new groupbox ("Language Type")
<< new radiobutton ("&Procedural")
<< new radiobutton ("&Functional")
<< new radiobutton ("&Object-oriented")
<< new endgroupbox;
this [2].after;
this << new checkbox ("Provides app framework")
<< new checkbox ("Has IDE");
this [6].under;
east();
this << new ok_button
<< new cancel_button;
}
};
[LISTING TWO]
//**** Linked list program that uses put_to ("<<") operator to append elements.
// by Jack Krupansky, 1993.
class MyListData
{
Print { cout << "Object of class "+this.class_name; }
};
struct MyListElement
{ MyListData data;
MyListElement next;
MyListElement (MyListData initialData)
{
data = initialData;
}
};
class MyList : MyListData
{ MyListElement head;
MyListElement tail;
public:
put_to (MyListData data)
{
MyListElement newElement = new MyListElement (data);
if (head) tail.next = newElement; // Append to non-empty list
else head = newElement; // Start from an empty list
tail = newElement; // Point to the new end of list
return this;
}
Print
{
for (int i = 0, MyListElement e = head; e; e = e.next)
e.data.Print();
}
};
class MyNumber : MyListData
{ int value;
MyNumber (int initialValue) { value = initialValue; }
Print { cout << " Number: " + value + "\n";}
};
{ int x, y;
MyPoint (int initialX,int initialY)
{ x = initialX; y = initialY; }
Print { cout << " Point: " + x + "," + y + "\n"; }
};
void main (void)
{ MyList list1 = new MyList;
MyList list2 = new MyList;
MyNumber n1 = new MyNumber (10);
MyNumber n2 = new MyNumber (20);
MyPoint p1 = new MyPoint (2,3);
MyPoint p2 = new MyPoint (4,5);
/* build the lists */
list1 << n1 << n2 << p1;
/* an object can be in more than one list at same time */
list2 << n2 << p1 << p2;
list2 << list1; // we can even put a list into another list
/* print the lists */
cout << "\nLIST1:\n"; list1.Print;
cout << "\nLIST2:\n"; list2.Print;
}
[LISTING THREE]
//*** Linked list program that subclasses "Linkable", by Ray Valdes, 1993. ***
class Linkable {
Linkable next;
Linkable GetNext { return next; }
SetNext(Linkable n) { next = n; }
Print { w << "Should override this method.\n"; }
};
class MyPoint : Linkable {
int x,y;
MyPoint(int xx,int yy) { x = xx; y = yy; }
Print { w << "Point ("+ x + "," + y + ")\n"; }
};
class MyNumber : Linkable {
int value;
MyNumber(int v) { value = v; }
Print { w << "Integer " + value + "\n"; }
};
class MyList : Linkable {
Linkable head,tail;
int count;
AddToList(Linkable item) {
count++;
if(! head) { head = tail = item; }
else { tail.SetNext(item); tail = item; }
}
Print {
for(int i = 0, Linkable x = head; i < count; i++, x = x.GetNext)
x.Print;
}
};
main { (w = new window).show; w << "Sample List Program in LIANA\n";
MyList list1 = new MyList;
MyList list2 = new MyList;
MyNumber n1 = new MyNumber (10);
MyNumber n2 = new MyNumber (20);
MyPoint p1 = new MyPoint (2,3);
// build the lists
list1.AddToList (n1);
list1.AddToList (n2);
// an object can be in more than one list at same time
list2.AddToList (n2);
list2.AddToList (p1);
// a list can contain another list as an element
// print the lists (should also print the content of any sublists)
w << "LIST1:\n"; list1.Print;
w << "LIST2:\n"; list2.Print;
w << "Done.\n";
}
Example 1:
startdrag (x1, y1, x2, y2)
{
w.line (old_x1 = x1, old_y1 = y1, old_x2 = x2, old_y2 = y2);
}
drag (x, y)
{
w.xor = true;
w.line (old_x1, old_y1, old_x2, old_y2 ); // Erase prev line
w.line (old_x1, old_y1, old_x2 = x, old_y2 = y); // Draw new line
w.xor = false;
}
Example 2:
startdrag (x1, y1, x2, y2)
{
w.line (old_x1 = x1, old_y1 = y1, old_x2 = x2, old_y2 = y2);
}
drag (x, y)
{
w.xor = true;
w.line (old_x1, old_y1, old_x2, old_y2); // Erase prev line
w.line (old_x1, old_y1, old_x2 = x, old_y2 = y); // Draw new line
w.xor = false;
}
enddrag (x, y)
{
if (! lines) lines = new array;
lines << new line (old_x1, old_y1, old_x2, old_y2);
}
paint
{
for (int i = 0; lines && i < lines.size; i++)
lines [i].draw (w);
}
Example 3:
main { window(); w.status_line_enabled = true; }
position (x,y) { w.status = x+","+y+" "; }
Example 4:
class MyList : array
{
Print
{
for (int i = 0, int n = size; i < n; i++)
if ((any e = this [i]).isa ("MyList"))
e.Print();
else
cout << e.class_name+": "+e.text+"\n";
}
};
//-------------------------------------------
void main (void)
{
MyList list1 = new MyList;
MyList list2 = new MyList;
int n1 = 10;
int n2 = 20;
point p1 = new point (2,3);
point p2 = new point (4,5);
/* build the lists */
list1 << n1 << n2 << p1;
/* an obj can be in more than one lst at same time */
list2 << n2 << p1 << p2;
list2 << list1; /* we can even put a list into another list */
/* print the lists */
cout << "\nLIST1:\n"; list1.Print;
cout << "\nLIST2:\n"; list2.Print;
}